package com.ruoyi.fsepc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fsepc.domain.StConfiguration;
import com.ruoyi.fsepc.service.IStConfigurationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 参数配置 参数配置Controller
 * 
 * @author ruoyi
 * @date 2020-02-27
 */
@Controller
@RequestMapping("/fse/configuration")
public class StConfigurationController extends BaseController
{
    private String prefix = "fsepc/configuration";

    @Autowired
    private IStConfigurationService stConfigurationService;

    @RequiresPermissions("fse:configuration:view")
    @GetMapping()
    public String configuration()
    {
        return prefix + "/configuration";
    }

    /**
     * 查询参数配置 参数配置列表
     */
    @RequiresPermissions("fse:configuration:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StConfiguration stConfiguration)
    {
        startPage();
        List<StConfiguration> list = stConfigurationService.selectStConfigurationList(stConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出参数配置 参数配置列表
     */
    @RequiresPermissions("fse:configuration:export")
    @Log(title = "参数配置 参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StConfiguration stConfiguration)
    {
        List<StConfiguration> list = stConfigurationService.selectStConfigurationList(stConfiguration);
        ExcelUtil<StConfiguration> util = new ExcelUtil<StConfiguration>(StConfiguration.class);
        return util.exportExcel(list, "configuration");
    }

    /**
     * 新增参数配置 参数配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存参数配置 参数配置
     */
    @RequiresPermissions("fse:configuration:add")
    @Log(title = "参数配置 参数配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StConfiguration stConfiguration)
    {
        return toAjax(stConfigurationService.insertStConfiguration(stConfiguration));
    }

    /**
     * 修改参数配置 参数配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StConfiguration stConfiguration = stConfigurationService.selectStConfigurationById(id);
        mmap.put("stConfiguration", stConfiguration);
        return prefix + "/edit";
    }

    /**
     * 修改保存参数配置 参数配置
     */
    @RequiresPermissions("fse:configuration:edit")
    @Log(title = "参数配置 参数配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StConfiguration stConfiguration)
    {
        return toAjax(stConfigurationService.updateStConfiguration(stConfiguration));
    }

    /**
     * 删除参数配置 参数配置
     */
    @RequiresPermissions("fse:configuration:remove")
    @Log(title = "参数配置 参数配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stConfigurationService.deleteStConfigurationByIds(ids));
    }
}
